<template>
    <div class="dialog" v-show="visible">
        <div class="home" @click="hide"></div>
        <div class="dialog-txt" style="{width:width}">
            <div class="dialog-header">
                <slot name="header">{{ title }}</slot>
                <button class="dialog-btn">
                    <i class="txt-dialog-i" @click="dialoghide">X</i>
                </button>
            </div>
            <div class="dialog-body">
                <slot name="body">中间</slot>
            </div>
            <div class="dialog-footer">
                <slot name="footer">底部</slot>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'MyDialog',
    props: {
        title: {
            type: String,
            default: '默认标题'
        },
        width: {
            type: String,
            default: '30%'
        },
        visible: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
        };
    },
    computed: {

    },
    created() {

    },
    mounted() {

    },
    watch: {

    },
    methods: {
        hide() {
            this.$emit('dialogvisible', !this.visible);
        },
        dialoghide() {
            this.$emit('dialoghide',!this.visible);
        }

    },
    components: {

    },
};
</script>

<style scoped lang="scss">
.dialog {
    .home {
        position: fixed;
        width: 100vw;
        height: 100vh;
        background-color: pink;
        background-color: rgba(240, 125, 125, 0.5);
        animation: homeFor 1s linear forwards;
    }

    .dialog-txt {
        // 盒子水平居中
        width: 30%;
        height: 250px;
        background-color: #fff;
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);

        .dialog-header {
            // position: absolute;
            // top: 5px;
            // left: 5px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }


}

// 定义透明动画
@keyframes homeFor {
    // 10%{}
    // 100%{}

    from {
        opacity: .2;
    }

    to {
        opacity: 1;
    }
}
</style>
